package com.selfdriving.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.selfdriving.BaseFragmentActivity;
import com.selfdriving.R;
import com.selfdriving.bean.Hotel;
import com.selfdriving.map.ScenicLocation;
import com.selfdriving.utils.Constant;
import com.selfdriving.utils.ViewFlipperView;

public class ActivityHotelExamine extends BaseFragmentActivity implements
		OnClickListener
{
	private TextView viewFlipperText;
	private LinearLayout VFlayout;
	private TextView title;
	private ImageButton imgBreak;
	int Pointe = 0;
	private LinearLayout linearLayout2;
	private LinearLayout linearLayout3;
	private LinearLayout linearLayout4;
	private LinearLayout linearLayout5;
	private LinearLayout linearLayout6;
	private TextView linearText1;
	private TextView linearText2;
	private TextView linearText3;
	private TextView linearText4;
	private TextView linearText5;
	private TextView linearText6;
	private Button gotoPlay;
	double lat = 0;
	double lng = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.activity_hotel_examine);
		initViews();
		initEvents();
	}

	@Override
	protected void initViews()
	{
		linearLayout2 = (LinearLayout) super.findViewById(R.id.hotel_linear2);
		linearLayout3 = (LinearLayout) super.findViewById(R.id.hotel_linear3);
		linearLayout4 = (LinearLayout) super.findViewById(R.id.hotel_linear4);
		linearLayout5 = (LinearLayout) super.findViewById(R.id.hotel_linear5);
		linearLayout6 = (LinearLayout) super.findViewById(R.id.hotel_linear6);
		gotoPlay = (Button) super.findViewById(R.id.hotel_goto);
		linearText1 = (TextView) super.findViewById(R.id.hotel_linear1_content);
		linearText2 = (TextView) super.findViewById(R.id.hotel_linear2_content);
		linearText3 = (TextView) super.findViewById(R.id.hotel_linear3_content);
		linearText4 = (TextView) super.findViewById(R.id.hotel_linear4_content);
		linearText5 = (TextView) super.findViewById(R.id.hotel_linear5_content);
		linearText6 = (TextView) super.findViewById(R.id.hotel_linear6_content);
		viewFlipperText = (TextView) super.findViewById(R.id.viewflipper_size);
		VFlayout = (LinearLayout) super.findViewById(R.id.vf_layout);
		title = (TextView) super.findViewById(R.id.top_text_middle);
		Hotel hotel = (Hotel) mApplication.listHotel.get(Pointe);
		lng = hotel.getLng();
		lat = hotel.getLat();
		title.setText(hotel.getName());
		linearText1.setText(hotel.getContent());
		linearText2.setText(hotel.getTel());
		linearText3.setText(hotel.getAds());
		linearText4.setText("￥" + hotel.getPrice());
		linearText5.setText(hotel.getPtss());
		linearText6.setText(hotel.getRoomType());
		imgBreak = (ImageButton) super.findViewById(R.id.head_break);
		imgBreak.setVisibility(View.VISIBLE);
		if (hotel.getImg4() != null)
		{
			mApplication.viewImg = new String[5];
			mApplication.viewImg[0] = hotel.getImg0();
			mApplication.viewImg[1] = hotel.getImg1();
			mApplication.viewImg[2] = hotel.getImg2();
			mApplication.viewImg[3] = hotel.getImg3();
			mApplication.viewImg[4] = hotel.getImg4();
		} else if (hotel.getImg3() != null)
		{
			mApplication.viewImg = new String[4];
			mApplication.viewImg[0] = hotel.getImg0();
			mApplication.viewImg[1] = hotel.getImg1();
			mApplication.viewImg[2] = hotel.getImg2();
			mApplication.viewImg[3] = hotel.getImg3();
		} else if (hotel.getImg2() != null)
		{
			mApplication.viewImg = new String[3];
			mApplication.viewImg[0] = hotel.getImg0();
			mApplication.viewImg[1] = hotel.getImg1();
			mApplication.viewImg[2] = hotel.getImg2();
		} else if (hotel.getImg1() != null)
		{
			mApplication.viewImg = new String[2];
			mApplication.viewImg[0] = hotel.getImg0();
			mApplication.viewImg[1] = hotel.getImg1();
		} else if (hotel.getImg0() != null)
		{
			mApplication.viewImg = new String[1];
			mApplication.viewImg[0] = hotel.getImg0();
		}
		ViewFlipperView flipperView = new ViewFlipperView(mApplication,
				ActivityHotelExamine.this, viewFlipperText,
				Constant.VF_HOTEL_DETAILS, mApplication.listHotel, Pointe);
		VFlayout.addView(flipperView.viewFlipper, layoutParams);
	}

	@Override
	protected void initEvents()
	{
		// TODO Auto-generated method stub
		imgBreak.setOnClickListener(this);
		linearLayout2.setOnClickListener(this);
		linearLayout3.setOnClickListener(this);
		linearLayout4.setOnClickListener(this);
		linearLayout5.setOnClickListener(this);
		linearLayout6.setOnClickListener(this);
		gotoPlay.setOnClickListener(this);
	}

	@Override
	public void onClick(View v)
	{
		// TODO Auto-generated method stub
		switch (v.getId())
		{
		case R.id.head_break:
			finish();
			break;
		case R.id.hotel_linear2:
			Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel://"
					+ linearText2.getText().toString().trim()));
			startActivity(intent);
			break;
		case R.id.hotel_goto:
			if (lng != 0 && lat != 0)
			{
				mApplication.geoPoint = new GeoPoint((int) (lng * 1e6),
						(int) (lat * 1e6));
				if (networkCheck.isNetworkConnected())
				{
					mApplication.exit = false;
					startActivity(ScenicLocation.class);
				} else
				{
					showShortToast("网络异常，无法为您导航。");
				}
			} else
			{
				showShortToast("未获得位置坐标，无法为您导航。");
			}
			break;
		}
	}

	@Override
	public void onBackPressed()
	{
		finish();
	}
}
